package vistas;

import interfaz.TDAManejoDatos;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import util.FechaUtil;

import controller.ControllerPrincipal;

import beans.EntidadBean;
import beans.RodamientoBean;
import beans.SolicitudCotizacionBean;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class SolicitarCotizacion extends BaseJFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7030896646166961016L;

	private JButton buttonSalir;
	private JButton buttonModificar;
	private JButton btnAlta;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JTextField jTextField6;
	private JButton jButton2;
	private JList jList1;
	private JButton jButton1;
	private JTextField jTextField5;
	private JTextField jTextField4;
	private JTextField jTextField3;
	private JTextField jTextField2;
	private JLabel jLabel4;
	private JLabel jLabel3;
	private JLabel jLabel2;
	private JTextField jTextField1;
	private JLabel jLabel1;
	private DefaultListModel listModel = new DefaultListModel();

	public SolicitarCotizacion() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Solicitar Cotizacion" + "");


			{
				buttonSalir = new JButton();
				getContentPane().add(buttonSalir);
				buttonSalir.setText("Salir");
				buttonSalir.setBounds(222, 244, 111, 23);
				buttonSalir.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						_exit();
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setBounds(40, 65, 44, 16);
				jLabel1.setText("Marca");
			}
			{
				btnAlta = new JButton();
				getContentPane().add(btnAlta);
				btnAlta.setText("Agregar");
				btnAlta.setBounds(110, 211, 77, 23);
				btnAlta.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						RodamientoBean rb = new RodamientoBean();
						rb.setMarca(jTextField1.getText());
						rb.setOrigen(jTextField2.getText());
						rb.setSufijo(jTextField3.getText());
						rb.setSerie(jTextField4.getText());
						rb.setCantidad(new Integer (jTextField5.getText()));
						listModel.addElement(rb);
					}
				});
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(110, 62, 90, 19);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Origen");
				jLabel2.setBounds(40, 97, 44, 16);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Cantidad");
				jLabel3.setBounds(37, 181, 73, 16);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("Serie");
				jLabel4.setBounds(39, 153, 44, 16);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("Sufijo");
				jLabel5.setBounds(39, 125, 44, 16);
			}
			{
				jTextField2 = new JTextField();
				getContentPane().add(jTextField2);
				jTextField2.setBounds(110, 93, 90, 19);
			}
			{
				jTextField3 = new JTextField();
				getContentPane().add(jTextField3);
				jTextField3.setBounds(111, 124, 90, 19);
				jTextField3.setText("AKA32");
			}
			{
				jTextField4 = new JTextField();
				getContentPane().add(jTextField4);
				jTextField4.setBounds(110, 152, 90, 19);
				jTextField4.setText("11111");
			}
			{
				jTextField5 = new JTextField();
				getContentPane().add(jTextField5);
				jTextField5.setBounds(110, 180, 90, 19);
				jTextField5.setText("20");
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Eliminar");
				jButton1.setBounds(555, 211, 77, 23);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						//jButton1ActionPerformed(evt);
						listModel.removeElementAt(jList1.getSelectedIndex());
					}
				});
			}
			{
				jList1 = new JList(listModel);
				jList1
						.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
				jList1.setLayoutOrientation(JList.VERTICAL);
				jList1.setVisibleRowCount(-1);

				JScrollPane listScroller = new JScrollPane(jList1);
				getContentPane().add(jList1);
				jList1.setBounds(275, 62, 357, 143);
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Solicitar Cotizacion");
				jButton2.setBounds(368, 244, 124, 23);
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						//jButton2ActionPerformed(evt);
						ControllerPrincipal c = ControllerPrincipal.getInstancia();
						SolicitudCotizacionBean s = new SolicitudCotizacionBean();
						s.setFecha(FechaUtil.getStringFromDate(FechaUtil.getHoy()));
						for (Object o: listModel.toArray()){
						s.getRodamientos().add((RodamientoBean) o);
						}
						try {
							EntidadBean cli=c.buscarCliente(jTextField6.getText());
							s.setCliente(cli);
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						try {
							c.cargarSolicitudCotizacion(s);
							_exit();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
						
					}
				});
			}
			{
				jTextField6 = new JTextField();
				getContentPane().add(jTextField6);
				jTextField6.setBounds(233, 21, 194, 19);
				jTextField6.setText("88888888888");
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("CUIL Cliente");
				jLabel6.setBounds(152, 22, 83, 16);
			}

			pack();
			this.setSize(671, 322);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void _exit() {
		this.dispose();
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {
		System.out.println("jButton1.actionPerformed, event="+evt);
		//TODO add your code for jButton1.actionPerformed
	}
	
	private void jButton2ActionPerformed(ActionEvent evt) {
		System.out.println("jButton2.actionPerformed, event="+evt);
		//TODO add your code for jButton2.actionPerformed
	}
}
